home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / DELPHI.SWG / 0012_Sizing of WIN95 Taskbar.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  2.4 KB  |  48 lines

  1. {
  2.   Pop this procedure into your main form's unit and call it from your
  3.   FormCreate procedure.  Under Win95 or WinNT w/Win95 shell, your main form
  4.   will fit perfectly in the client area of the screen in a wsNormal state.
  5.   The only parm for the proc is the name of your main form.  If Win95 or
  6.   WinNT/wWin95 shell is NOT running, your form will open in a wsMaximized
  7.   state.
  8.  
  9.   This may or may not be the only way to accomplish this task, but it works.
  10.  
  11.   Freeware. No guarantees, promises or responsibility. Use to your heart's
  12.   content.  Just give me credit: Peter M. Jagielski
  13.                                  73737,1761@compuserve.com
  14. }
  15.  
  16. procedure SizeForTaskBar(MyForm: TForm);
  17. var
  18.   TaskBarHandle: HWnd;    { Handle to the Win95 Taskbar }
  19.   TaskBarCoord:  TRect;   { Coordinates of the Win95 Taskbar }
  20.   CxScreen,               { Width of screen in pixels }
  21.   CyScreen,               { Height of screen in pixels }
  22.   CxFullScreen,           { Width of client area in pixels }
  23.   CyFullScreen,           { Heigth of client area in pixels }
  24.   CyCaption:     Integer; { Height of a window's title bar in pixels }
  25. begin
  26.   TaskBarHandle := FindWindow('Shell_TrayWnd',Nil); { Get Win95 Taskbar handle }
  27.   if TaskBarHandle = 0 then { We're running Win 3.x or WinNT w/o Win95 shell, so just maximize }
  28.     MyForm.WindowState := wsMaximized
  29.   else { We're running Win95 or WinNT w/Win95 shell }
  30.     begin
  31.       MyForm.WindowState := wsNormal;
  32.       GetWindowRect(TaskBarHandle,TaskBarCoord);      { Get coordinates of Win95 Taskbar }
  33.       CxScreen      := GetSystemMetrics(SM_CXSCREEN); { Get various screen dimensions and set form's width/height }
  34.       CyScreen      := GetSystemMetrics(SM_CYSCREEN);
  35.       CxFullScreen  := GetSystemMetrics(SM_CXFULLSCREEN);
  36.       CyFullScreen  := GetSystemMetrics(SM_CYFULLSCREEN);
  37.       CyCaption     := GetSystemMetrics(SM_CYCAPTION);
  38.       MyForm.Width  := CxScreen - (CxScreen - CxFullScreen) + 1;
  39.       MyForm.Height := CyScreen - (CyScreen - CyFullScreen) + CyCaption + 1;
  40.       MyForm.Top    := 0;
  41.       MyForm.Left   := 0;
  42.       if (TaskBarCoord.Top = -2) and (TaskBarCoord.Left = -2) then { Taskbar on either top or left }
  43.         if TaskBarCoord.Right > TaskBarCoord.Bottom then { Taskbar on top }
  44.           MyForm.Top  := TaskBarCoord.Bottom
  45.         else { Taskbar on left }
  46.           MyForm.Left := TaskBarCoord.Right;
  47.     end;
  48. end;